package com.jinxin.platform.cdfaceacs.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinxin.platform.cdfaceacs.mapper.CdattendancerecordUserMapper;
import com.jinxin.platform.cdfaceacs.pojo.domains.CdattendancerecordUser;
import com.jinxin.platform.cdfaceacs.pojo.form.UserPageForm;
import com.jinxin.platform.cdfaceacs.service.CdattendancerecordUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 考勤记录模块-用户信息表(CdattendancerecordUser)表服务实现类
 *
 * @author yangjie
 * @since 2021-04-23 10:03:12
 */
@Service("cdattendancerecordUserService")
public class CdattendancerecordUserServiceImpl implements CdattendancerecordUserService {
    @Resource
    private CdattendancerecordUserMapper cdattendancerecordUserMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public CdattendancerecordUser queryById(String id) {
        return this.cdattendancerecordUserMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param cdattendancerecordUser 实例对象
     * @return 对象列表
     */
    @Override
    public List<CdattendancerecordUser> queryAll(CdattendancerecordUser cdattendancerecordUser) {
        return this.cdattendancerecordUserMapper.queryAll(cdattendancerecordUser);
    }

    /**
     * 新增数据
     *
     * @param cdattendancerecordUser 实例对象
     * @return 实例对象
     */
    @Override
    public CdattendancerecordUser insert(CdattendancerecordUser cdattendancerecordUser) {
        this.cdattendancerecordUserMapper.insert(cdattendancerecordUser);
        return cdattendancerecordUser;
    }

    /**
     * 修改数据
     *
     * @param cdattendancerecordUser 实例对象
     * @return 实例对象
     */
    @Override
    public CdattendancerecordUser update(CdattendancerecordUser cdattendancerecordUser) {
        this.cdattendancerecordUserMapper.update(cdattendancerecordUser);
        return this.queryById(cdattendancerecordUser.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.cdattendancerecordUserMapper.deleteById(id) > 0;
    }

    @Override
    public CdattendancerecordUser getUserByWorkNo(String workNo) {
        return this.cdattendancerecordUserMapper.getUserByWorkNo(workNo);
    }

    @Override
    public PageInfo<CdattendancerecordUser> pageList(UserPageForm pageForm) {
        Page<CdattendancerecordUser> page = PageHelper.startPage(pageForm.getPageNum(), pageForm.getPageSize());
        CdattendancerecordUser query = new CdattendancerecordUser();
        BeanUtils.copyProperties(pageForm, query);
        PageInfo<CdattendancerecordUser> pageInfo = new PageInfo<>(cdattendancerecordUserMapper.queryAll(query));
        pageInfo.setPages(page.getPages());
        pageInfo.setTotal(page.getTotal());
        return pageInfo;
    }
}
